﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace AbetEvaluation
{
	public partial class OutcomeResult : System.Web.UI.Page
	{
		int score;
		int total;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				score = 0;
				total = 0;
			}
		}

		protected void gvResults_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				String answer = DataBinder.Eval(e.Row.DataItem, "Answer").ToString();
				String correct = DataBinder.Eval(e.Row.DataItem, "CorrectAnswer").ToString();

				if (answer.Equals(correct))
				{
					e.Row.Cells[2].BackColor = Color.LightGreen;
					e.Row.Cells[3].Font.Bold = true;
					score += (int)DataBinder.Eval(e.Row.DataItem, "Points");
				}
				else
					e.Row.Cells[2].BackColor = Color.Salmon;

				total += (int)DataBinder.Eval(e.Row.DataItem, "Points");
			}
			else if (e.Row.RowType == DataControlRowType.Footer)
			{
				e.Row.Cells[3].Font.Size = FontUnit.Larger;
				e.Row.Cells[3].Text = score.ToString();

				lblGrade.Text = "Your score: " + Business.Taken.GetGrade(Guid.Parse(Request.QueryString["id"])).ToString("f0") + "%";
			}
		}
	}
}